# from rest_framework import authentication
# from rest_framework.exceptions import AuthenticationFailed
# # from .jwt_utils import verify_jwt_token
#
#
# class JWTAuthentication(authentication.BaseAuthentication):
#     def authenticate(self, request):
#         # 从请求头中获取 JWT
#         token = request.META.get('HTTP_AUTHORIZATION')
#         if not token or not token.startswith('Bearer '):
#             return None
#
#             # 去除 'Bearer ' 前缀
#         token = token[7:]
#
#         # 验证 JWT
#         payload, user = verify_jwt_token(token)
#         if not user:
#             raise AuthenticationFailed('Invalid token.')
#
#             # 返回用户对象和认证信息（这里可以返回 None，因为我们已经有了用户对象）
#         return user, None
#
#     def authenticate_header(self, request):
#         return 'Bearer realm="api"'